package DCSource.Start;

import java.io.File;
import java.util.ArrayList;

public class StartManager {
	public StartManager(){};
	private ArrayList<File> Folder = new ArrayList<File>();
	private ArrayList<File> Files = new ArrayList<File>();
	private ArrayList<DCSource.ConfigManager.Manager> Manager = new ArrayList<DCSource.ConfigManager.Manager>();
	public void addFolder(String Fol){
		File m = new File(Fol);
		Folder.add(m);
	}
	public void addFile(String File){
		File m = new File(File);
		Files.add(m);
	}
	public void revFolder(String Fol){
		File m = new File(Fol);
			for (int I=0;I<Folder.size();I++){
				if (Folder.get(I).equals(m)){
					Folder.remove(I);
				}
			}
	}
	public void revFile(String File){
		File m = new File(File);
			for (int I=0;I<Folder.size();I++){
				if (Folder.get(I).equals(m)){
					Folder.remove(I);
				}
			}
	}
	public void addManager(String File, DCSource.ConfigManager.Manager MG){
		File m = new File(File);
		if (MG!=null){
			MG.setTitle(File);
			Manager.add(MG);
		}
	}
	public void revManager(DCSource.ConfigManager.Manager MG){
		for (int I=0;I<Manager.size();I++){
			if (Manager.get(I).equals(MG)){
				Manager.remove(I);
			}
		}
	}
	public void revManager(String File){
		for (int I=0;I<Manager.size();I++){
			if (Manager.get(I).getTitle().equals(File)){
				Manager.remove(I);
			}
		}
	}
	public void saveManager(){
		for (int I=0;I<Manager.size();I++){
			Manager.get(I).saveToFile(Manager.get(I).getTitle());
		}
	}
	public void setManager(DCSource.ConfigManager.Manager mg, String File){
		for (int I=0;I<Manager.size();I++){
			if (Manager.get(I).getTitle().equals(File)){
				Manager.set(I, mg);
			}
		}
	}
	public DCSource.ConfigManager.MGm getManager(){
		DCSource.ConfigManager.MGm returning = new DCSource.ConfigManager.MGm();
		for (int I=0;I<Manager.size();I++){
			returning.add(Manager.get(I),true);
		}
		return returning;
	}
	public void init(){
		for (int I=0;I<Folder.size();I++){
			if (Folder.get(I).exists()==false){
				Folder.get(I).mkdirs();
			}
		}
		for (int I=0;I<Files.size();I++){
			if (Files.get(I).exists()==false){
				DCSource.filer save = new DCSource.filer();
				save.writeText("",Files.get(I).toString());
			}
		}
		for (int I=0;I<Manager.size();I++){
			File exist = new File(Manager.get(I).getTitle());
			if (exist.exists()==false){
				Manager.get(I).saveToFile(Manager.get(I).getTitle());
			}else{
				DCSource.ConfigManager.Manager zw = new DCSource.ConfigManager.Manager();
				zw.loadIn(Manager.get(I).getTitle());
				setManager(zw,Manager.get(I).getTitle());
			}
		}
	}
}
